import {Modal} from "@arco-design/web-vue";
import {h} from "vue";

export class Dialog {

  static alert(msg: string) {
    Modal.info({
      content: msg, simple: false, hideTitle: true, footer: false, width: 'auto', bodyStyle: {
        margin: '20px 30px', padding: '0'
      }
    })
  }

  static confirm(msg: string, onConfirm: (e?: Event) => void, onCancel?: (e?: Event) => void) {
    const modalInstance = Modal.confirm({
      content: msg, maskClosable: false, simple: false, hideTitle: true, width: 'auto', footer: () => h('div', {
        style: {
          display: 'flex',
          justifyContent: 'space-evenly',
          padding: '0',
          margin: '0',
          columnGap: '20px'
        }
      }, [h('button', {
        style: {
          padding: '8px 16px',
          background: '#f2f3f5',
          border: 'none',
          borderRadius: '4px',
          cursor: 'pointer',
        },
        onClick: () => {
          modalInstance.close()
          onCancel?.()
        }
      }, '取消'),
        h('button', {
          style: {
            padding: '8px 16px',
            background: '#1d6ee8',
            color: 'white',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer',
          },
          onClick: () => {
            modalInstance.close()
            onConfirm?.()
          }
        }, '确定')
      ])
    })
  }
}